package com.panopset.sf.apps.blackjack;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JPanel;

import com.panopset.refactorsf.TPanel;
import com.panopset.refactorsf.TitledPanel;

public class RulesConfig {

    private final BlackjackSwingConfig bsc;

    public RulesConfig(final BlackjackSwingConfig blackjackSwingConfig) {
        bsc = blackjackSwingConfig;
    }

    private JPanel p;
    private JPanel rp;

    JPanel getPanel() {
        if (p == null) {
            p = new JPanel(new GridBagLayout());
            p.setName("Config");
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.anchor = GridBagConstraints.NORTH;
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.weightx = 1.0;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            p.add(getRulesPanel(), gbc);
            gbc.gridy = 1;
            gbc.weightx = 1.0;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.weighty= 1.0;
            p.add(getCountingStrategy().getPanel(), gbc);
        }
        return p;
    }


    private CountingStrategy csp;
    private CountingStrategy getCountingStrategy() {
        if (csp == null) {
            csp = new CountingStrategy(bsc);
        }
        return csp;
    }

    JPanel getRulesPanel() {
        if (rp == null) {
            JPanel p0 = new TPanel();
            JPanel p1 = new TPanel();
            JPanel p2 = new TPanel();
            p0.add(bsc.getEuropeanCB().getGui());
            p0.add(bsc.getHitSoft17CB());
            p0.add(bsc.getBlackjack6to5());
            p0.add(bsc.getShowCountCB());
            p1.add(bsc.getDasCB());
            p1.add(bsc.getRsaCB());
            p1.add(bsc.getFastDealCB());
            p1.add(bsc.getBasicStrategyVariationsOnlyCB());
            p1.add(bsc.getLsaCB());
            p2.add(bsc.getIncrTF().getPanel());
            p2.add(bsc.getStakeTF().getPanel());
            p2.add(bsc.getDecksTF().getPanel());
            p2.add(bsc.getSeatsTF().getPanel());
            rp = new TitledPanel("Rules", new GridBagLayout(), "Configure rules to match your favorite casino.").getPanel();
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.anchor = GridBagConstraints.NORTH;
            gbc.gridx = 0;
            gbc.gridy = 0;
            rp.add(p0, gbc);
            gbc.gridy = 1;
            rp.add(p1, gbc);
            gbc.gridy = 2;
            gbc.weighty= 1.0;
            rp.add(p2, gbc);
        }
        return rp;
    }
}
